<template>
	<div class="content">
		<div class="base">
			<Form inline class="fl">
				<Input type="text" placeholder="扣除编号" class="w200 m-r10" v-model.trim="tradeId" />
				<Input type="text" placeholder="会员ID" class="w200 m-r10" v-model.trim="userId" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getConditionQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累积扣除ESTATE:
								<span class="blue" v-text="collectList.sumEstate == null ? '0.00' : Fixed(collectList.sumEstate)">0</span>
							</td>
							<td>累积扣除USDT:
								<span class="blue" v-text="collectList.sumUsdt == null ? '0.00' : Fixed(collectList.sumUsdt)">0</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon>导出
		</Button>
		<Table stripe :columns="columns" :data="conditionQuery" ref="table" :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
		<Modal v-model="modal1" title="充值会员详情" width="40%" :footer-hide="true">
			<Table stripe :columns="columns1" :data="userDetail" ref="table" :loading="loading"></Table>
		</Modal>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dcShow: false,
				dataValue: ['', ''], // 时间段值
				conditionQuery: [], // 条件查询的结果
				userDetail: [], //会员详情
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				tradeId: '',
				userId: '',
				typeId: '',
				modal: false,
				modal1: false, //充值会员详情
				myUpList: [],
				downList: [],
				jsonData: [],
				loading: true,
				collectList: '0.00',
				columns: [{
						title: '扣除会员ID',
						key: 'receiveUuid',
						align: 'center',
						render: (h, params) => {
							return h('div', {
									style: {
										cursor: "pointer",
										color: '#2db7f5'
									},
									on: {
										click: () => {
											this.userDetail = [];
											this.modal1 = true;
											this.axios.get('/admin/accounting/recharge/rechargeable/' + params.row.receiveUuid).then(res => {
												if(res.data.code == 200) {
													this.userDetail.push(res.data.data);
												}
											})
										}
									}
								},
								params.row.receiveUuid == null ? '#' : params.row.receiveUuid);
						}
					},
					{
						title: '扣除编号',
						key: 'tradeId',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.tradeId == null ? '#' : params.row.tradeId);
						}
					},
					{
						title: '扣除数量',
						key: 'num',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num));
						}
					},
					{
						title: '币种类型',
						key: 'coinType',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.coinType == null ? '#' :  this.coinIdFormat(params.row.coinType));
						}
					},
					{
						title: '用户',
						key: 'receiveName',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.receiveName == null ? '#' : params.row.receiveName);
						}
					},
					{
						title: '操作人名称',
						key: 'rechargeName',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.rechargeName == null ? '#' : params.row.rechargeName)
						}
					},
					{
						title: '操作人手机号',
						key: 'rechargePhone',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.rechargePhone == null ? '#' : params.row.rechargePhone)
						}
					},
					{
						title: '备注',
						key: 'remark',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.remark == null ? '#' : params.row.remark)
						}
					},
					{
						title: '扣除时间',
						key: 'createTime',
						align: 'center',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					}
				],
				columns1: [{
						title: '名称',
						align: 'center',
						key: 'userName',
						render: (h, params) => {
							return h('div', params.row.userName == null ? '#' : params.row.userName)
						}
					},
					{
						title: '会员类型',
						align: 'center',
						key: 'levelId',
						render: (h, params) => {
							return h('div', 'VIP');
						}
					},
					{
						title: '注册时间',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
					{
						title: '他的上级',
						align: 'center',
						key: 'puuid',
						render: (h, params) => {
							return h('div', params.row.puuid == null ? '#' : params.row.puuid)
						}
					},
				]
			}
		},
		mounted() {
			this.$Message.config({ // 配置弹窗的位置
				top: 250
			})
			let token = localStorage.getItem('mytoken')
			this.axios.get('/admin/accounting/recharge/getRechargeCumulative', {
				params: {
					rechargeType: 2
				}
			}).then(res => {
				if(res.data.code == 200) {
					this.collectList = res.data.data;
				}
			})
			this.getQuery() // 充值列表查询
		},
		methods: {
			getTime(daterange) {
				this.dataValue = daterange
			},
			exportData() { // 导出
				this.jsonData = [];
				this.dcShow = true;
				this.axios.get('/admin/accounting/recharge/getRechargeList', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: this.userId,
						tradeId: this.tradeId,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59',
						rechargeType: 2
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.axios.get('/admin/accounting/recharge/getRechargeList', {
							params: {
								current: this.page, // 当前页【可选，默认1】
								size: res.data.data.total, // 每页记录数【可选，默认20】
								tradeId: this.tradeId,
								uuid: this.userId,
								startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
								endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59',
								rechargeType: 2
							}
						}).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.jsonData.push({
										receiveUuid: this.downList[index].receiveUuid,
										tradeId: this.downList[index].tradeId,
										num: this.Fixed(this.downList[index].num),
										coinType: this.coinIdFormat(this.downList[index].coinType),
										receiveName: this.downList[index].receiveName,
										rechargeName: this.downList[index].rechargeName,
										rechargePhone: this.downList[index].rechargePhone,
										remark: this.downList[index].remark,
										createTime: this.stringToTime(this.downList[index].createTime),
									})
								})
								let str = `扣除会员ID,扣除编号,扣除编号,币种类型,账户,操作人名称,操作人手机号,备注,充值时间\n`;
								this.downLoad(this.jsonData, str, '扣除列表');
							}
						})
					}
				})
			},
			getQuery() { // 充值列表查询
				this.loading = true;
				let token = localStorage.getItem('mytoken')
				this.axios.get('/admin/accounting/recharge/getRechargeList', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: '',
						tradeId: '',
						startTime: '', // 起始日期
						endTime: '', // 结束日期
						rechargeType: 2,
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.conditionQuery = res.data.data.records;
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].paymentDate = '\t' + this.stringToTime(row.paymentDate);
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery(page) { // 充值列表分页查询
				this.loading = true;
				let token = localStorage.getItem('mytoken')
				this.axios.get('/admin/accounting/recharge/getRechargeList', {
					params: {
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: this.userId,
						tradeId: this.tradeId,
						startTime: '', // 起始日期
						endTime: '', // 结束日期
						rechargeType: 2
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.conditionQuery = res.data.data.records
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].paymentDate = '\t' + this.stringToTime(row.paymentDate);
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			getConditionQuery() { // 充值列表条件查询
				this.loading = true;
				let token = localStorage.getItem('mytoken')
				this.page = 1;
				this.axios.get('/admin/accounting/recharge/getRechargeList', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: this.userId,
						tradeId: this.tradeId,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59',
						rechargeType: 2
					}
				}).then(res => {
					if(res.data.code == 200 || res.data.code == 500) {
						this.conditionQuery = res.data.data.records;
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].paymentDate = '\t' + this.stringToTime(row.paymentDate);
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
		}
	}
</script>

<style>

</style>